package dji.ux.ext.setting.battery;

import androidx.annotation.NonNull;

import dji.keysdk.FlightControllerKey;
import dji.thirdparty.io.reactivex.Flowable;
import dji.ux.beta.base.DJISDKModel;
import dji.ux.beta.base.WidgetModel;
import dji.ux.beta.base.uxsdkkeys.ObservableInMemoryKeyedStore;
import dji.ux.beta.util.DataProcessor;

public class FlyTimeModel extends WidgetModel {
    private final DataProcessor<Integer> flyTimeProcess;

    public FlyTimeModel(@NonNull DJISDKModel djiSdkModel,
                        @NonNull ObservableInMemoryKeyedStore keyedStore) {
        super(djiSdkModel, keyedStore);

        flyTimeProcess = DataProcessor.create(0);
    }

    public Flowable<Integer> getFlyTime() {
        return flyTimeProcess.toFlowable();
    }

    @Override
    protected void inSetup() {
        FlightControllerKey flyTimeKey =
                FlightControllerKey.create(FlightControllerKey.FLY_TIME_IN_SECONDS);
        bindDataProcessor(flyTimeKey, flyTimeProcess, (value) -> {
            Integer second = (Integer) value;
            if (second != null) {
                flyTimeProcess.onNext(second);
            }
        });
    }

    @Override
    protected void inCleanup() {

    }

    @Override
    protected void updateStates() {

    }
}
